package graphics;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JPanel;

/**
 * @author sthankan
 *
 */
public abstract class AbstractNumberButtonPanel extends JPanel {
	private static final int MIN_NO = 1;
	private static final int MAX_NO = 9;
	
	public AbstractNumberButtonPanel(Dimension d) throws IOException {
		super();
		this.setPreferredSize(d);
		this.setLayout(new GridLayout(MIN_NO, MAX_NO));
		addNumbersToPanel();
	}
	
	private void addNumbersToPanel() throws IOException {
		for(int i=MIN_NO;i<=MAX_NO;i++) {
			final NumberButton nb = new NumberButton(i);
			nb.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					numberPressed(nb.getNumber());
				}
			});
			this.add(nb);
		}
	}
	
	public abstract void numberPressed(int no);
}
